package com.hdaccp.xingmu.controller;

import com.hdaccp.xingmu.dao.DirectionDao;
import com.hdaccp.xingmu.entity.Direction;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.UnsupportedEncodingException;
import java.util.List;

@Controller
@RequestMapping("/dir")
public class DirectionCon {
    @Autowired
    private DirectionDao directionDao;
    @RequestMapping("/d")
    @ResponseBody
    public List<Direction> list (){
        return directionDao.findAll();
    }

    @RequestMapping("/tj")
    @ResponseBody
    public List<Direction> add(Direction direction)throws UnsupportedEncodingException {

        directionDao.save(direction);
        return directionDao.findAll();
    }
    @RequestMapping("/sc")
    @ResponseBody
    public List<Direction> del(Long id){
        directionDao.deleteById(id);
        return directionDao.findAll();
    }
    @RequestMapping("/upda")
    @ResponseBody
    public List<Direction> xiugai(Direction direction)throws UnsupportedEncodingException {

        directionDao.save(direction);
        return directionDao.findAll();
    }
}
